import {useState, useEffect} from 'react';

function Demo (){
    const [count, setCount] = useState(0);
    useEffect(() => {
      let id = setInterval(() => {
        setCount(count => {
            // console.log(count);
            return count + 1;
        })
      }, 1000);
      return () => clearInterval(id);
    }, []);
    // useEffect中组件卸载的时候执行；
  
    return <h1>{count}</h1>;
}
export default Demo;